
<script>
 $(document).ready(function(){
    $(".update_version").click(function(){
        var inventory_id = $(this).attr("id");
        $.ajax({
      	   type: "POST",
      	   url:"<?php echo  base_url();?>model/get_inventory_for_layout",
      	   data: "inventory_id="+inventory_id,
           dataType:'json', 
      	   success: function(msg){          	  
        	   $("#mod_id_notice").html(msg.mod);
        	   $("#category_id_notice").html(msg.category);
        	   $("#version_id").html(msg.version);
        	   $("#count_notice").html("<font color='red'>最多可更新"+msg.count+"份资料</font>");
        	   $("#mod_id").val(msg.mod_id);
        	   $("#category_ids").val(msg.category_id);
        	   $("#inventory_id").val(msg.inventory_id);
        	   $("#pre_count").val(msg.count);
        	   $("#pre_version").val(msg.pre_verison);
        	   $("#current_version").html(msg.pre_verison);
        	   $("#pre_version_id").val(msg.pre_version_id);
  	    	   $("#version_detail").modal();
      	   }
      	});
    })

    $("#submit").click(function(){
 	var inventory_id = $("#inventory_id").val();
     var mod_id = $("#mod_id").val();
     var category_id = $("#category_ids").val();
     var count = $("#count").val();
     var version_id = $("#version_id").val();
     var pre_version = $("#pre_version").val();
     var pre_version_id = $("#pre_version_id").val();
     var pre_count = $("#pre_count").val();
     var codes = $("#codes").val();
     
     var version = $("#version_id").find("option:selected").text();
     var version=version.replace(".","");
     var version=version.replace(".","");
     var preversion=pre_version.replace(".","");            
     var preversion=preversion.replace(".","");
     
     if(version_id==""){
        alert("更新至版本不能空");
        return false;
     }
      
     if(parseInt(version)<=parseInt(preversion)){
   	  alert('更新至版次必须高于当前版次');
   	  return false;
     } 

     if(codes==""){
         alert("更新单据号不能空！")
         return false;
     }
     if(count==""){
         alert('更新份数不能空！');
         return false;
     }
     var str = "pre_version_id="+pre_version_id+"&codes="+codes+"&mod_id="+mod_id+"&category_id="+category_id+"&version_id="+version_id+"&pre_version="+pre_version+"&pre_count="+pre_count+"&count="+count+"&inventory_id="+inventory_id;
     $.ajax({
     	   type: "POST",
     	   url:"<?php echo  base_url();?>model/update_inventory",
     	   data: str, 
     	   success: function(msg){          	  
                  if(msg==1){
                    alert('操作成功');
                    $(".simplemodal-close").click();
                    window.location.reload();
                  }else{
                    alert(msg);
                  }
     	   }
     	});
    })
	$("#mod_id").change(function(){
         var mod_id = $(this).val();
         if(mod_id!=""){
    	 $.ajax({
        	   type: "POST",
        	   url:"<?php echo  base_url();?>model/get_category",
        	   data: "mod_id="+mod_id,
        	   success: function(msg){
            	   $("#category_id").html("");
            	   $("#category_id").html(msg);
        	   }
          });   
    	 $("#version_form").submit();
         }else{
        	 $("#version_form").submit();
         }
     })     

    $("#category_id").change(function(){
         $("#version_form").submit();
     })
     $("#see").click(function(){
         $("#see_all").val('1');
         $("#version_form").submit();
     })
     
 })
     function check_version(v){
        var v = $(v).find("option:selected").text();
        var pre_version = $("#current_version").html();
        var v=v.replace(".","");
        var v=v.replace(".","");
        var pre_version=pre_version.replace(".","");            
        var pre_version=pre_version.replace(".","");

        if(parseInt(v)<=parseInt(pre_version)){
            alert('更新至版次必须高于当前版次');
        }
    }
</script>    
		<div id="center-column">
			<div class="top-bar">
				<div class="breadcrumbs"><a href="#">首页</a></div>
			</div><br />
		  <div class="select-bar">
		  <?php echo form_open('model/inventory',array('id'=>'version_form'));?> 
		    <label>型号：</label><label><select id="mod_id" name="mod_id">
		                      <option value="">全部型号</option>
		                   <?php foreach($mod as $k=>$val){?>
		                      <option value="<?php echo $val->mod_id;?>" <?php if(isset($mod_id)&&($mod_id==$val->mod_id)){?>selected=true<?php }?>><?php echo $val->name;?></option>
		                   <?php }?>
		                 </select>
		    </label>
		    <label>种类：</label>
		    <label><select id="category_id" name="category_id"><option value="">全部资料种类</option></select></label>
		    <label>
		    <input type="text" name="textfield" /><input type="hidden" value="0" name="see_all" id="see_all"/>
		    </label>
		    <label>
			<?php if(isset($mod_id)&&($mod_id!="")){?><input type="submit" name="see"  id="see"value="查看全部" /><?php }?><input type="submit" name="Submit" value="搜索" /><?php if($see_all=="1"){?>该型号总共有库存：<?php echo $cou;?>份<?php }?>
			</label>
		  </form>	
		  </div>
			<div class="table">
				
				
				<table class="listing" cellpadding="0" cellspacing="0">
					<tr>
						<th class="first" width="22">ID</th>
						<th>型号</th>
						<th>资料种类</th>						
						<th>资料版本</th>
						<th>库存量</th>
						<th>版本更新</th>
					</tr>
			    <?php foreach($inventory as $k=>$val):if($val->count!=0){?>		
					<tr>
                        <td><?php echo $start;?></td> 
                        <td><?php foreach($mod as $j=>$m){ if($val->mod_id==$m->mod_id){echo $m->name;}}?></td>
                        <td style="text-align:left;padding-left:5px;width:300px;"><?php foreach($category as $j=>$m){ if($val->category_id==$m->category_id){echo $m->name;}}?></td>                                               
                        <td><?php foreach($version as $j=>$m){ if($val->version_id==$m->version_id){echo $m->name;}}?></td>
                        <td><?php echo $val->count;?></td>  
                        <td><?php if($val->update==1){?><span id="<?php echo $val->inventory_id;?>" class="update_version">更新版次</span> <?php }?></td>
                       </tr>
				<?php $start++;}endforeach;?>						
				</table>
				<?php echo $page;?>
			</div>
		</div>
	</div>
		<div id="version_detail">
			<link href="<?php echo  base_url();?>css/lhgcalendar.css" rel="stylesheet" type="text/css" />
    <script language="javascript" src="<?php echo base_url();?>js/lhgcalendar.min.js"></script>	
    <script>
      $(document).ready(function(){
    	  $('.date-pick').datePicker({startDate:'1996.01.01'});
      })
    </script>
		<table class="listing form" cellpadding="0" cellspacing="0" style="width:550px;">
	               <input type="hidden" id="pre_count" />
	               <input type="hidden" id="pre_version" />
	               <input type="hidden" id="pre_version_id" />
	               <input type="hidden" id="mod_id" />
	               <input type="hidden" id="category_ids" />
	               <input type="hidden" id="inventory_id" />
					<tr>
						<th  colspan="2"  align="center">更新库存版次</th>
					</tr>
					<tr>
						<td style="width:100px;text-align:right;"><strong>型号：</strong></td>
						<td style="text-align:left;">
						<span id="mod_id_notice"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<font color="#FF0000">版次更新状态下，型号，资料种类不可以更改</font></td>
					</tr>
					<tr>
						<td style="width:100px;text-align:right;"><strong>资料种类：</strong></td>
						<td style="text-align:left;"><span id="category_id_notice"></span></td>
					</tr>
					<tr>
						<td style="width:100px;text-align:right;"><strong>资料当前版本：</strong></td>
						<td style="text-align:left;"><span id="current_version"></span></td>
					</tr>
					<tr>
						<td style="width:100px;text-align:right;"><strong>更新至版本：</strong></td>
						<td style="text-align:left;"><select name="version_id" id="version_id" onchange="check_version(this)"></select></td>
					</tr>
                    <tr class="bg">
						<td style="width:100px;text-align:right;"><strong>更新单据号：</strong></td>
						<td style="text-align:left;"><input type="text" class="text" name="codes" id="codes" value="" /></td>
					</tr>
					<tr class="bg">
						<td style="width:100px;text-align:right;"><strong>更新份数：</strong></td>
						<td style="text-align:left;"><input type="text" class="text" name="count" id="count" value=""  onKeyUp="this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?'':this.value.match(/^[0-9]*[1-9][0-9]*$/)" onafterpaste="this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?'':this.value.match(/^[0-9]*[1-9][0-9]*$/)" /><span id="count_notice"></span></td>
					</tr>
					<tr>
						<td colspan="2"><input type="button" value="提交" class="button" id="submit"/></td>			
					</tr>
				</table></div>	
	<div id="footer"></div>
</div>

<input type="hidden" id="version_mod_id" value="<?php echo $mod_id;?>"/>
<input type="hidden" id="version_category_id" value="<?php echo $category_id;?>"/>
</body>
</html>
<script>
  $(document).ready(function(){
	  var mod_id = $("#version_mod_id").val();
	  var category_id = $("#version_category_id").val();
		 $.ajax({
		  	   type: "POST",
		  	   url:"<?php echo  base_url();?>model/get_category",
		  	   data: "mod_id="+mod_id,
		  	   success: function(msg){
		      	   $("#category_id").html("");
		      	   $("#category_id").html(msg);
			      	 $("select[name=category_id]").val(category_id);
		  	   }
		    });    
   })
</script>
